<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use DB;
class Art extends Model
{
    protected $primaryKey='art_id';
    public $timestamps=false;

    protected $cats = array();
	public function __construct(){
    	parent::__construct();
    	$this->cats = DB::table('cats')->where('cat_status',1)->get();
    }

	public function getTree($parentid=0,$lev=0){
    	$tree = array();
		foreach ($this->cats as $c) {
            if ($c->parentid == $parentid){
            	$c->lev = $lev;
            	$tree[] = $c;
            	$tree = array_merge($tree,$this->getTree($c->cat_id,$lev+1));
            }
        }
        return $tree;
    }

}
